package com.example.smartplay.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.smartplay.entity.Notice;
import com.example.smartplay.entity.Result;
import com.example.smartplay.mapper.NoticeMapper;
import com.example.smartplay.service.NoticeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 
 * @since 2024-07-11
 */
@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements NoticeService {

    @Autowired
    private NoticeMapper noticeMapper;
    //查询全部通知
    @Override
    public List<Notice> list() {
        return noticeMapper.list();
    }
    //新增通知
    @Override
    public void add(Notice notice) {
        noticeMapper.insert(notice);
    }
    //删除通知
    @Override
    public void delete(List<Integer> ids) {
        noticeMapper.deleteBatchIds(ids);
    }
    //根据id查询通知
    @Override
    public Notice find(Integer id) {
        return noticeMapper.selectById(id);
    }
    //修改通知
    @Override
    public void update2(Notice notice) {
        noticeMapper.updateById(notice);
    }

    //分页查询通知

    @Override
    public Result getnotice(String keyword, Integer pageNum, Integer pageSize) {
        Page<Notice> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<Notice> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(StringUtils.hasText(keyword), Notice::getTitle, keyword).or()
                .like(StringUtils.hasText(keyword), Notice::getContent, keyword).or()
                .like(StringUtils.hasText(keyword), Notice::getClubId, keyword);
        return Result.success(noticeMapper.selectPage(page, wrapper));
    }


}
